package com.casems.config;

import com.casems.filter.CrossFilter;
import com.casems.intercepter.AuthIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {


    @Autowired
    AuthIntercepter authIntercepter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        registry.addInterceptor(authIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/loginSms","/code","/checkCode","/user/register");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

    }

    @Bean
    public FilterRegistrationBean<CrossFilter> crossFilterBean(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new CrossFilter());
        registrationBean.addUrlPatterns("*");

        registrationBean.setOrder(-200);
        return registrationBean;
    }
}
